//
//  DBMainTabBar.swift
//  大波微博swift
//
//  Created by 大波 on 16/2/27.
//  Copyright © 2016年 zhaojin. All rights reserved.
//

import UIKit

protocol DBMainTabBarDelegate: NSObjectProtocol {
    
    func mainTabBarButtomDidClick()
}

class DBMainTabBar: UITabBar {

    weak var composeDelegate: DBMainTabBarDelegate?
    
    override func layoutSubviews() {
        
        super.layoutSubviews()
//        print(__FUNCTION__)
        let width = frame.width / 5 + 5
        
        composeButton.frame = CGRect(x: 0, y: 0, width: width, height: frame.height)
        
        composeButton.center = CGPoint(x: frame.width * 0.5, y: frame.height * 0.5)
    }
    
    //MARK: - 懒加载
    ///tabBar中间的加号按钮属性
    lazy var composeButton: UIButton = {
        
        let btn = UIButton()
        
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(btn)
        
        btn.addTarget(self, action: "composeBtnDidClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        return btn
    }()
    
    func composeBtnDidClick() {
//        print(__FUNCTION__)
        self.composeDelegate?.mainTabBarButtomDidClick()
    }
}
